<template>
	<view class="">
		<view :class="{'dropdown_mask': status1}"></view>
		<view class="dropdown">
			<view class="item" v-for="(item,index) in dropItem" :key="item.id" @click="dropClick(item,index)">
				<text>{{item.title}}</text> <u-icon :name="item.title==title?'arrow-up':'arrow-down'"
					color="#c8c9cc"></u-icon>
			</view>
			<view class="dowMsk" :style="{height:status1?'300rpx':'0rpx'}">
				<scroll-view scroll-y="true" style="height: 300rpx">
					<u-cell-group v-if="id !== 3">
						<u-cell :title="ite.title" v-for="ite in selectOptions" :key="ite.id" :isLink="false"
							@click="fenleiClick(ite)">
							<text slot="value" class="u-slot-value">
								<!-- <text v-if="ite.title==dropItem[index].title">
									√
								</text> -->
							</text>
						</u-cell>
					</u-cell-group>
					<view class="filter-group" v-else>
						<view v-for="ite in selectOptions" :key="ite.id">
							<text class="filter-title">{{ite.title}}</text>
							<view class="detail-list">
								<view @click="fenleiClick(detail)" class="filter-detail" v-for="(detail,index) in ite.list" :key="index">
									<text class="tip" :style="{backgroundColor:detail.color}">{{detail.tip}}</text>
									<text class="detail-title">{{detail.title}}</text>
								</view>
							</view>
						</view>
					</view>
				</scroll-view>
		
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "filter-select",
		data() {
			return {
				status1: false,
				optionsList: [],
				title: '',
				id: '',
				index: 10,
				selectOptions: [],
				dropItem: [{
						id: 1,
						selectId: '',
						title: '全部分类',
						options: [
						]
					},
					{
						id: 2,
						title: '默认排序',
						options: [
							{
								id: 1,
								title: '默认排序'
							},
							{
								id: 2,
								title: '离我最近'
							},
							
						]
					},
					{
						id: 3,
						title: '筛选',
						options: [{
								id: 1,
								title: '营业状态',
								list:[
									{
										title:'营业中',
										tip:'营',
										color:'green'
									},
									{
										title:'休息中',
										tip:'休',
										color:'gray'
									},
									{
										title:'可预订',
										tip:'订',
										color:'pink'
									},
								],
							},
							{
								id: 2,
								title: '店铺优惠',
								list:[
									{
										title:'下单返卷',
										tip:'返',
										color:'red'
									},
									{
										title:'满立送',
										tip:'送',
										color:'blue'
									},
									{
										title:'优惠打折',
										tip:'惠',
										color:'red'
									},
									{
										title:'首单优惠',
										tip:'首',
										color:'blue'
									},
									{
										title:'免配送费',
										tip:'免',
										color:'blue'
									},
								],
							},
							{
								id: 3,
								title: '店铺属性',
								list:[
									{
										title:'在线支付',
										tip:'付',
										color:'pink'
									},
									{
										title:'可选择优惠',
										tip:'可',
										color:'blue'
									},
									{
										title:'10分钟超时',
										tip:'超',
										color:'red'
									},
									{
										title:'25分钟超时',
										tip:'超',
										color:'red'
									},
									{
										title:'品牌店',
										tip:'品',
										color:'pink'
									},
									{
										title:'新店',
										tip:'新',
										color:'pink'
									},
								],
							},
							
						]
					}
				]
			};
		},
		mounted() {
				this.$req('GET',this.$api.fenLlist,{}).then(res =>{
					console.log('哈哈哈哈', res)
					// this.lists = res.data.list.map(item => ({ name: item.title }));
					let lists = res.data.list.map((item)=>{
						return {
							id:item.id,
							title:item.title
						}
					})
					this.$set(this.dropItem[0],"options",lists)
					
				})
			
		},
		methods: {
			dropClick(item, index) {
				this.selectOptions = item.options
				this.id = item.id
				if (index == this.index) {
					this.status1 = !this.status1
				} else {
					this.status1 = true
				}
				this.index = index

			},
			selectOption(option, data) {
				console.log(data);
				this.status = data.status
				this.title = data.title
				this.optionsList = option
			},
			fenleiClick(item) {
				this.$set(this.dropItem[this.index], "title", item.title)
				this.status1 = false
				// this.$emit('tabClick', `我选择的是${item.title}`)
				this.$emit('tabClick', {
				  text: `我选择的是${item.title}`,
				  id: this.id,
				  item_id:item.id
				});
				console.log(item,'查看这个item是什么')
				
				uni.setStorageSync('fenlei',item.id)
				uni.setStorageSync('fenleiTitle',item.title)
				
			}
		}
	}
</script>

<style scoped lang="scss">
	.dropdown_mask {
		width: 100vw;
		height: 100vh;
		z-index: 1000;
		position: fixed;
		top: 0;
		left: 0;
		background-color: rgba(0, 0, 0, 0.5);
	}
	.u-slot-value {
		width: 50%;
		color: #ff9900;
		background-color: #fff;
	}
	.filter-group {
		margin-top: 10rpx;
		.detail-list {
			display: flex;
			align-items: center;
			flex-wrap: wrap;
			margin-bottom: 20rpx;
			border-top: 1px solid lightgrey;
			border-bottom: 1px solid lightgrey;
			margin-top: 14rpx;
		}
		.filter-title {
			padding: 6rpx 10rpx;
			color: gray;
		}
		.filter-detail {
			display: flex;
			align-items: center;
			width: 33.3%;
			height: 70rpx;
			line-height: 70rpx;
			padding: 10rpx 10rpx;
			box-sizing: border-box;
			overflow: hidden;
			text-overflow: ellipsis;
			&:not(:last-child) {
				border-right: 1px solid lightgrey;
			}
			.tip {
				border-radius: 10rpx;
				margin-right: 10rpx;
				width: 40rpx;
				height: 40rpx;
				font-size: 12px;
				color:#fff;
				display: flex;
				    align-items: center;
				    justify-content: center;
			}
		}
	}
	.item {
		display: flex;
		align-items: center;
		position: relative;
		z-index: 1002;
		background-color: #fff;
		width: 33.3%;
		padding: 0 28rpx;
		box-sizing: border-box;
		text-align: center;
		height: 60rpx;
		line-height: 30rpx;
		text {
			padding-right: 8rpx;
			font-size: 26rpx;
		}
	}
	:deep(.u-cell__body) {
		background-color: lightgray;
	}
	.dowMsk {
		position: absolute;
		background-color: #fff;
		top: 50rpx;
		left: 0rpx;
		width: 100%;
		z-index: 999;
		overflow: hidden;
		transition: all .3s linear;
	}
	.u-cell {
		background-color: lightgrey;
	}
	.dropdown {
		display: flex;
		margin: 15rpx 0;
		position: relative;
		z-index: 1002;
		&__mask {
			position: absolute;
			z-index: 9;
			background: rgba(0, 0, 0, .3);
			width: 100%;
			left: 0;
			top: 0;
			bottom: 0;
		}

	}

	.dowMsk {
		position: absolute;
		background-color: #fff;
		top: 50rpx;
		left: 0rpx;
		width: 100%;
		z-index: 999;
		overflow: hidden;
		transition: all .3s linear;
	}
</style>